package com.swss.test;

public class Son extends Father implements TestIf {

	public Son(int age) {

		super(age);

	}

	public void look() {

		System.out.println(this.age);
	}

	public void maopao() {
		int arr[] = { 5, 6, 4, 3, 2, 7, 10, 20, 15, 1 };

		int temp = 0;
		for (int i = 0; i < arr.length - 1; i++) {

			for (int j = 0; j < arr.length - i - 1; j++) {
				if (arr[j] > arr[j + 1]) {
					temp = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = temp;
				}
			}

		}

		for (int k = 0; k < arr.length; k++) {
			System.out.print(arr[k] + ",");
		}
	}

	public int[] data = { 49, 38, 65, 97, 76, 13, 27 };

	public int kuai(int i, int j, int[] arr) {

		int key = arr[i];
		int temp = 0;

		while (i < j) {
			while (i < j && key > arr[j]) {
				j--;
			}
			// temp = arr[i];
			arr[i] = arr[j];
			// arr[j] = temp;

			while (i < j && key < arr[i]) {
				i++;
			}
			// temp = arr[i];
			arr[j] = arr[i];
			// arr[j] = temp;

		}
		arr[i] = key;
		return i;

	}

	public void show() {
		System.out.println("==");
		for (int i = 0; i < this.data.length; i++) {
			System.out.print(this.data[i] + ",");
		}
		System.out.println("==");
	}

	public void sort(int i, int j) {
		if (i < j) {
			int m = this.kuai(i, j, this.data);
			System.out.println(m);

			this.sort(i, m - 1);
			this.sort(m + 1, j);
		}
	}

	public static void main(String args[]) {
		Son s = new Son(28);
		s.look();

		Singleton.getInstance().rest();
		s.sort(0, s.data.length - 1);
		s.show();
		// s.maopao();

		// TODO 自动生成方法存根
		quicksort qs = new quicksort();
		int data[] = { 44, 22, 2, 32, 54, 22, 88, 77, 99, 11 };
		qs.data = data;
		qs.sort(0, qs.data.length - 1);
		qs.display();
	}

	public void ccc() {
		// TODO Auto-generated method stub

	}

}

class quicksort {
	public int data[];

	private int partition(int sortArray[], int low, int hight) {
		int key = sortArray[low];

		while (low < hight) {
			while (low < hight && sortArray[hight] >= key)
				hight--;
			sortArray[low] = sortArray[hight];

			while (low < hight && sortArray[low] <= key)
				low++;
			sortArray[hight] = sortArray[low];
		}
		sortArray[low] = key;
		return low;
	}

	public void sort(int low, int hight) {
		if (low < hight) {
			int result = partition(data, low, hight);
			sort(low, result - 1);
			sort(result + 1, hight);
		}

	}

	public void display() {
		for (int i = 0; i < data.length; i++) {
			System.out.print(data[i]);
			System.out.print(" ");
		}
	}

}